package com.yuanchu.store.controller;

import com.yuanchu.common.exception.BizCodeEnum;
import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.store.dto.QueryUserParamsDto;
import com.yuanchu.store.entity.YoshopUserBalanceLogEntity;
import com.yuanchu.store.service.YoshopUserBalanceLogService;
import com.yuanchu.store.utils.SecurityUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-19 15:02
 */
@RestController
@RequestMapping("balance")
public class UserBalanceLogController {

    @Resource
    private YoshopUserBalanceLogService userBalanceLogService;

    @GetMapping("/log/list")
    public R queryUserPointsLogList(@RequestParam Integer page) {
        Integer userId = SecurityUtil.getUserId();
        PageResult<YoshopUserBalanceLogEntity> userBalanceLog = userBalanceLogService.queryUserBalanceLog(userId, page);
        Map<String, Object> map = new HashMap<>();
        map.put("list", userBalanceLog);
        return R.ok().put("data", map);
    }
    @GetMapping("/log")
    public R queryUserPointsLog(QueryUserParamsDto param) {
        PageResult<YoshopUserBalanceLogEntity> userBalanceLog = userBalanceLogService.queryUserPointsLog(param);
        Map<String, Object> map = new HashMap<>();
        map.put("list", userBalanceLog);
        return R.ok().put("data", map);
    }

    @PostMapping("/log/insert")
    public R insertUserBalanceLog(@RequestBody YoshopUserBalanceLogEntity balanceLog){
        boolean flag = false;
        if (!flag){
            return R.error(BizCodeEnum.EDIT_USER_BALANCE_LOG_EXCEPTION.getCode(), BizCodeEnum.EDIT_USER_BALANCE_LOG_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
